package chpt02;

public class LoopDemo06 {
	public static void main(String[] args) {
		int[] arr = { 21, 12, 33, 35, 14, 16, 27, 18, 19 };
		int[] newarr = new int[9];
		int odd = 0; // odd记录奇偶数个数
		// 统计数组arr中的奇数个数
		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] & 1) == 1) {
				odd++;
			}
		}
		int j = 0;
		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] & 1) == 1) {
				newarr[j] = arr[i];
				j++;
			} else {
				newarr[odd] = arr[i];
				odd++;
			}
		}
		for (int num : newarr) {
			System.out.print(num + " ");
		}
	}
}
